package com.yanqu.road.logic.activity.entername;

import com.yanqu.road.entity.activity.entername.EnterNameParam;
import com.yanqu.road.entity.activity.entername.UserEnterName;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.cross3.activity.EnterNameProto;

public class ChannelEnterNameHelper {

    public static EnterNameParam parseFromMsg(EnterNameProto.ChannelEnterNameAddReqMsg reqMsg){

        EnterNameParam param = new EnterNameParam(
                reqMsg.getActivityId(),
                reqMsg.getUserKey().getChannelId(),
                reqMsg.getUserKey().getServerId(),
                reqMsg.getUserKey().getUserId(),
                reqMsg.getZoneId(),
                PlayerBasePb.parseToUserBaseInfo(reqMsg.getUserBaseInfo())
        );
        return param;
    }

    public static EnterNameParam parseFromMsg(int activityId, int channelId, long serverId, EnterNameProto.ChannelEnterNameAddMsg msg){

        EnterNameParam param = new EnterNameParam(
                activityId,
                channelId,
                serverId,
                msg.getUserId(),
                msg.getZoneId(),
                PlayerBasePb.parseToUserBaseInfo(msg.getUserBaseInfo())
        );
        return param;
    }

    public static EnterNameProto.UserEnterNameMsg.Builder buildUserEnterNameMsg(UserEnterName userEnterName){
        EnterNameProto.UserEnterNameMsg.Builder builder = EnterNameProto.UserEnterNameMsg.newBuilder();
        builder.setActivityId(userEnterName.getActivityId());
        builder.setUserId(userEnterName.getUserId());
        builder.setChannelId(userEnterName.getChannelId());
        builder.setServerId(userEnterName.getServerId());
        builder.setZoneId(userEnterName.getZoneId());
        builder.setGroupId(userEnterName.getGroupId());
        return builder;
    }

    public static UserEnterName parseFromMsg(EnterNameProto.UserEnterNameMsg msg){
        UserEnterName userEnterName = new UserEnterName();
        if(msg.hasActivityId()) {
            userEnterName.setActivityId(msg.getActivityId());
        }
        userEnterName.setUserId(msg.getUserId());
        if(msg.hasChannelId()) {
            userEnterName.setChannelId(msg.getChannelId());
        }
        if(msg.hasServerId()){
            userEnterName.setServerId(msg.getServerId());
        }
        userEnterName.setZoneId(msg.getZoneId());
        if(msg.hasGroupId()){
            userEnterName.setGroupId(msg.getGroupId());
        }
        return userEnterName;
    }

}
